package com.zzj.ecology.framework.listener;

import com.zzj.ecology.common.constant.Constant;
import com.zzj.ecology.common.utils.MessageUtils;
import com.zzj.ecology.framework.manager.AsyncManager;
import com.zzj.ecology.framework.manager.async.AsyncTaskFactory;
import com.zzj.ecology.framework.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.Date;

/**
 * @ClassName CustomizeHttpSessionListener
 * @Description TODO
 * @Author zhijun zeng at 15:13 2020/4/25
 * @Version 1.0
 *
 * //https://www.liangzl.com/get-article-detail-169763.html
 **/
//@Component
public class CustomizeHttpSessionListener implements HttpSessionListener {

    @Autowired
    private AsyncTaskFactory asyncTaskFactory;
    @Autowired
    private AsyncManager asyncManager;

    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        System.out.println("-----");

    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        String curr = (String) httpSessionEvent.getSession().getAttribute("curr");
        String username = SecurityUtils.getUsername();

        asyncManager.execute(asyncTaskFactory.recordLoginInfor(username,
                Constant.LOGIN_SUCCESS,new Date(), MessageUtils.message("user.logout.success")));
    }
}
